package com.guanyu.u2cache.controller;


import com.guanyu.u2cache.domain.Result;
import com.guanyu.u2cache.domain.Teacher;
import com.guanyu.u2cache.service.CacheTestService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Slf4j
@RestController
@RequestMapping("/cache")
public class TestCacheController {

    @Resource
    private CacheTestService cacheTestService;


  //  @ApiOperation(value = "teacher")
    @GetMapping("/findTeacher/")
    public Result findTeacher() throws Exception {
        log.info("开始测试tea");
        long start = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
            cacheTestService.findAllInfo();
        }
        log.info("结束测试tea" + (System.currentTimeMillis() - start));
        return Result.success();
    }

   // @ApiOperation(value = "removeTeacher")
    @GetMapping("/removeTeacher/")
    public Result removeTeacher() throws Exception {
        log.info("开始删除tea");
        cacheTestService.removeAllInfo();
        log.info("结束删除tea");
        return Result.success();
    }

  //  @ApiOperation(value = "teacher2")
    @GetMapping("/findTeacher/level2")
    public Result findTeacher2() throws Exception {
        log.info("开始测试tea");
        Teacher result = cacheTestService.findAllInfoLevel2();
        log.info("结束测试tea" + result);
        return Result.success(result);
    }

   // @ApiOperation(value = "map")
    @GetMapping("/findMap/")
    public Result findMap() throws Exception {
        log.info("开始测试map");
        Map<String, Teacher> result = cacheTestService.findAllMap();
        log.info("结束测试map" + result.get("aaa"));
        return Result.success(result);
    }

  //  @ApiOperation(value = "map2")
    @GetMapping("/findMap/level2")
    public Result findMap2() throws Exception {
        log.info("开始测试map");
        Map<String, Teacher> result = cacheTestService.findAllMapLevel2();
        log.info("结束测试map" + result.get("aaa"));
        return Result.success(result);
    }

  //  @ApiOperation(value = "list")
    @GetMapping("/findLists/")
    public Result findLists() throws Exception {
        log.info("开始测试list");
        List<Teacher> result = cacheTestService.findLists();
        log.info("结束测试list" + result);
        return Result.success(result);
    }

  //  @ApiOperation(value = "list2")
    @GetMapping("/findLists/level2")
    public Result findLists2() throws Exception {
        log.info("开始测试list");
        List<Teacher> result = cacheTestService.findListsLevel2();
        log.info("结束测试list" + result);
        return Result.success(result);
    }

   // @ApiOperation(value = "listByInfo")
    @GetMapping("/findListsByInfo/")
    public Result findListsByInfo() throws Exception {
        log.info("开始测试listinfo");
        Teacher t = new Teacher();
        t.setName("hahaha");
        List<Teacher> result = cacheTestService.findListsByInfo(t);
        log.info("结束测试listinfo" + result);
        return Result.success(result);
    }

//    @ApiOperation(value = "findListsByInfoParam")
//    @GetMapping("/findListsByInfo/param")
//    public Result findListsByInfoParam() throws Exception {
//        log.info("开始测试listinfo");
//        Teacher t = new Teacher();
//        t.setName("hahaha");
//        List<Teacher> result = cacheTestService.findListsByInfo(t);
//        log.info("结束测试listinfo" + result);
//        return Result.success(result);
//    }

  //  @ApiOperation(value = "listByInfoRemove")
    @GetMapping("/findListsByInfo/remove")
    public Result findListsByInfoRemove() throws Exception {
        log.info("开始删除");
        List<Teacher> result = cacheTestService.findListsByInfo("hahaha");
        log.info("结束测试listinfo" + result);
        return Result.success(result);
    }

   // @ApiOperation(value = "listByInfo2")
    @GetMapping("/findListsByInfo/level2")
    public Result findListsByInfo2() throws Exception {
        log.info("开始测试listinfo");
        Teacher t = new Teacher();
        t.setName("hahaha");
        List<Teacher> result = cacheTestService.findListsByInfoLevel2(t);
        log.info("结束测试listinfo" + result);
        return Result.success(result);
    }

   // @ApiOperation(value = "listByInfo2/remove")
    @GetMapping("/findListsByInfo/level2/remove")
    public Result findListsByInfo2Remove() throws Exception {
        log.info("开始remove listinfo");
        Teacher t = new Teacher();
        t.setName("hahaha");
        List<Teacher> result = cacheTestService.removeListsByInfoLevel2(t);
        log.info("结束remove listinfo" + result);
        return Result.success(result);
    }

   // @ApiOperation(value = "listByInfo2/put")
    @GetMapping("/findListsByInfo/level2/put")
    public Result findListsByInfo2put() throws Exception {
        log.info("开始put listinfo");
        Teacher t = new Teacher();
        t.setName("hahaha");
        List<Teacher> result = cacheTestService.putListsByInfoLevel2(t);
        log.info("结束put listinfo" + result);
        return Result.success(result);
    }

   // @ApiOperation(value = "eventPub")
    @GetMapping("/eventPub/pub")
    public Result eventPub() throws Exception {
        log.info("事件发布开始");
        Teacher t = new Teacher();
        t.setName("hahaha");
        cacheTestService.pub(t);
        return Result.success();
    }


  //  @ApiOperation(value = "一级事件缓存")
    @GetMapping("/eventCache/level1/get")
    public Result eventCacheLevel1Get() throws Exception {
        log.info("开始put listinfo");
        Teacher t = new Teacher();
        t.setName("hahaha");
        List<Teacher> result = cacheTestService.eventCacheLevel1Get(t);
        cacheTestService.eventCacheLevel1Get1(t);
        log.info("结束put listinfo" + result);
        return Result.success(result);
    }

  //  @ApiOperation(value = "一级事件缓存删除")
    @GetMapping("/eventCache/level1/remove")
    public Result eventCacheLevel1remove() throws Exception {
        log.info("开始删除 listinfo");
        Teacher t = new Teacher();
        t.setName("hahaha");
        cacheTestService.eventCacheLevel1remove(t);
        log.info("结束删除 listinfo");
        return Result.success();
    }

  //  @ApiOperation(value = "二级事件缓存")
    @GetMapping("/eventCache/level2/get")
    public Result eventCacheLevel2Get() throws Exception {
        log.info("开始put listinfo");
        Teacher t = new Teacher();
        t.setName("hahaha");
        List<Teacher> result = cacheTestService.eventCacheLevel2Get(t);
        cacheTestService.eventCacheLevel2Get1(t);
        log.info("结束put listinfo" + result);
        return Result.success(result);
    }

   // @ApiOperation(value = "二级事件缓存删除")
    @GetMapping("/eventCache/level2/remove")
    public Result eventCacheLevel2remove() throws Exception {
        log.info("开始删除 listinfo");
        Teacher t = new Teacher();
        t.setName("hahaha");
        cacheTestService.eventCacheLevel2remove(t);
        log.info("结束删除 listinfo");
        return Result.success();
    }
}
